# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=nsia
pkgver=1.0.6
pkgrel=4
pkgdesc='A website scanner that monitors websites in realtime in order to detect defacements, compliance violations, exploits, sensitive information disclosure and other issues.'
url='http://threatfactor.com/Products/'
groups=('blackarch' 'blackarch-scanner' 'blackarch-webapp' 'blackarch-defensive')
arch=('any')
license=('custom:nsia')
depends=('java-environment' 'swt' 'systemd' 'libstdc++5')
makedepends=('dos2unix')
source=('http://threatfactor.com/Support/Files/ThreatFactor%20NSIA.zip'
        'http://threatfactor.com/Support/Files/NSIA.Definitions'
        'nsia.tmpfiles.conf'
        'rhino.jar')
sha512sums=('be091d9cf148acb88d76560ae205d5d646982c04'
          'e76eba574b37b9df153192fd8329d9a936600fc1'
          'eaaf1e631a8cddaf86e4ce05cd6997962ac023dc'
          'c8b24b8803e5295030bc2a209cfd6ce0001b92b4')
noextract=('rhino.jar')
install="$pkgname.install"

prepare() {
  dos2unix etc/config.ini

  rm lib/swt.jar
}

package() {
  unset _JAVA_OPTIONS

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/var/lib/$pkgname/var"

  install -Dm 644 nsia.tmpfiles.conf "$pkgdir/usr/lib/tmpfiles.d/nsia.conf"
  install -Dm 644 -t "$pkgdir/usr/share/nsia/doc" doc/"Quick Start Guide.pdf" \
    doc/AUTHORS NSIA.Definitions
  install -Dm 644 doc/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm 644 bin/nsia.jar "$pkgdir/usr/share/$pkgname/bin/nsia.jar"
  install -Dm 644 etc/config.ini "$pkgdir/usr/share/$pkgname/etc/config.ini"
  install -Dm 644 etc/mime.types "$pkgdir/usr/share/$pkgname/etc/mime.types"
  install -Dm 644 rhino.jar "$pkgdir/usr/share/$pkgname/lib/rhino.jar"

  find lib -type f -exec install -Dm644 '{}' "$pkgdir"/usr/share/nsia/'{}' \;

  ln -s /usr/share/java/swt.jar "$pkgdir/usr/share/nsia/lib/swt.jar"

  echo -e '#!/usr/bin/env bash\n\nunset _JAVA_OPTIONS\n\ncd /var/lib/nsia/var\njava -Xbootclasspath/p:../lib/rhino.jar -jar /usr/share/nsia/bin/nsia.jar "$@"' > "$pkgdir/usr/bin/nsia"

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

